package com.cj.wtrails

import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.Window
import android.view.WindowManager
import androidx.fragment.app.FragmentActivity
import com.tbruyelle.rxpermissions2.RxPermissions
import kotlinx.android.synthetic.main.activity_start.*

/**
 * 启动页
 * */
class LunchActivity : FragmentActivity() {
    private val ISFIRST = "isFirst"
    @SuppressLint("CheckResult")
    override fun onCreate(savedInstanceState: Bundle?) {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
            val lp = this.window.attributes
            lp.layoutInDisplayCutoutMode =
                WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
        }
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_start)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            RxPermissions(this)
                .request(
                    Manifest.permission.CAMERA,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.ACCESS_COARSE_LOCATION
                )
                .subscribe { granted ->
                    if (granted) {
                        init()
                    } else {
                        finish()
                    }
                }
        } else {
            init()
        }


    }

    private fun init() {
        iv_start.postDelayed({
            startActivity(Intent(this, TvMainActivity::class.java))
            /* val isFirst = SimpleConfig.getParam(this, ISFIRST, true) as Boolean
             if (isFirst) {
                 SimpleConfig.setParam(this, ISFIRST, false)
                  startActivity(Intent(this, LoginActivity::class.java))
             } else {
                 if (UserCache.getInstance().hasLogin()) {
                      startActivity(Intent(this, MainActivity::class.java))
                 } else {
                      startActivity(Intent(this, LoginActivity::class.java))
                 }
             }*/
            
            finish()

        }, 1500)
    }

}